#!/bin/sh
#
# 1.1 90/06/20 dfk@cwi.nl

umask 077

# remove tempfiles upon exit or interruption
trap "rm -f /tmp/getipbcst*.$$" 0 1 2

# create awk script 
cat <<'EOF' >/tmp/getipbcstawk.$$
{
	pairpkt[$1":"$2] += $3;
	pairbyt[$1":"$2] += $4;
}

END {
	for (p in pairpkt)
	{
		split(p, pp, ":");
		printf "%-15.15s %-15.15s %6d %9d\n", pp[1], pp[2], pairpkt[p], pairbyt[p];
	}
}
EOF

# grep the interesting lines from stdin, format, sort and write to stdout
egrep "\.0 |\.255 " | \
awk -f /tmp/getipbcstawk.$$ | \
sort -t. +0 -1n +1 -2n +2 -3n
